home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mgr / lib / sin.c < prev    next >
Text File  |  1989-01-24  |  2KB  |  72 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: sin.c,v 4.1 88/06/21 13:40:58 bianchi Exp $
  9.     $Source: /tmp/mgrsrc/lib/RCS/sin.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /tmp/mgrsrc/lib/RCS/sin.c,v $$Revision: 4.1 $";
  12.  
  13. /*    sine and cosine routines
  14.  *    input:    degrees (integer) 
  15.  *    output:    sine/cosine * 1024
  16.  */
  17.  
  18. /*    sin table 0-90 degrees * 1024 */
  19.  
  20. int sintab[] = {
  21.     0, 18, 36, 54, 71, 89, 107, 125, 143, 160,
  22.     178, 195, 213, 230, 248, 265, 282, 299, 316, 333,
  23.     350, 367, 384, 400, 416, 433, 449, 465, 481, 496,
  24.     512, 527, 543, 558, 573, 587, 602, 616, 630, 644,
  25.     658, 672, 685, 698, 711, 724, 737, 749, 761, 773,
  26.     784, 796, 807, 818, 828, 839, 849, 859, 868, 878,
  27.     887, 896, 904, 912, 920, 928, 935, 943, 949, 956,
  28.     962, 968, 974, 979, 984, 989, 994, 998, 1002, 1005,
  29.     1008, 1011, 1014, 1016, 1018, 1020, 1022, 1023, 1023,
  30.     1024, 1024,
  31.     } ;
  32.  
  33. int
  34. isin(n)
  35. register int n;        /* angle in degrees */
  36.    {
  37.    if (n < 0)
  38.       return(-isin(-n));
  39.  
  40.    while (n >= 360)
  41.       n -= 360;
  42.  
  43.    if (n < 90)
  44.       return( sintab[n]);
  45.    else if (n < 180)
  46.       return( sintab[180-n]);
  47.    else if (n < 270)
  48.       return( -sintab[n-180]);
  49.    else
  50.       return( -sintab[360-n]);
  51.    }
  52.  
  53. int
  54. icos(n)
  55. register int n;
  56.    {
  57.    if (n < 0)
  58.       n = -n;
  59.  
  60.    while (n >= 360)
  61.       n -= 360;
  62.  
  63.    if (n < 90)
  64.       return( sintab[90-n]);
  65.    else if (n < 180)
  66.       return( -sintab[n-90]);
  67.    else if (n < 270)
  68.       return( -sintab[270-n]);
  69.    else
  70.       return( sintab[n-270]);
  71.    }
  72.